<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>扫一扫</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../../css/mui.min.css">
		<link rel="stylesheet" href="../../css/global.css">
		<link rel="stylesheet" href="../../css/style.css">
		<style>
			#bcid {
				width: 100%;
				position: fixed;
				top: 44px;
				bottom: 0px;
				text-align: center;
			}
			.tip {
				color: #FFFFFF;
				font-weight: bold;
				text-shadow: 0px -1px #103E5C;
			}
		</style>
	</head>

	<body style="background-color:#000000;">
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<a id="lighting" class="mui-action-menu mui-icon mui-icon-bars mui-pull-right"></a>
			<h1 class="mui-title">扫一扫</h1> 
		</header>
		<div class="mui-content">
			<div id="bcid">
				<div style="height:40%"></div>
				<p class="tip">...载入中...</p>
			</div>
		</div>

		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/utils/h.js"></script>
		<script src="../../js/constant.js"></script>
		<script src="../../js/common.js"></script>
		<script src="../../js/utils/base64.js"></script>
		<script src="../../js/utils/md5.js"></script>
		<script src="../../js/utils/sortMap.js"></script>
		<script src="../../js/utils/http.js"></script>
		<script src="../../js/app.js"></script>
		<!-- 基础js end -->

		<script type="text/javascript" charset="utf-8">
			(function($, doc) {
				var ws = null,
					wo = null;
				var scan = null;


				$.init();

				$.plusReady(function() {
					// 从上一个页面取值
					var self = plus.webview.currentWebview();
					 // 获取上一个页面传过来的参数并显示到页面
					 var state = self.state;
					
					// 获取窗口对象
					ws = plus.webview.currentWebview();
					wo = ws.opener();

					// 开关闪光灯
					var bFlash = false;
					var AVCaptureDevice = null;
					var Camera = null;

					h('#lighting').tap(function() {
						bFlash = !bFlash;
						scan.setFlash(bFlash);
					})

					// 二维码扫描成功
					var onmarked = function(type, result, file) {
						switch (type) {
							case plus.barcode.QR:
								type = 'QR';
								break;
							case plus.barcode.EAN13:
								type = 'EAN13';
								break;
							case plus.barcode.EAN8:
								type = 'EAN8';
								break;
							case plus.barcode.AZTEC:
								type = 'AZTEC';
								break;
							case plus.barcode.DATAMATRIX:
								type = 'DATAMATRIX';
								break;
							case plus.barcode.UPCA:
								type = 'UPCA';
								break;
							case plus.barcode.UPCE:
								type = 'UPCE';
								break;
							case plus.barcode.CODABAR:
								type = 'CODABAR';
								break;
							case plus.barcode.CODE39:
								type = 'CODE39';
								break;
							case plus.barcode.CODE93:
								type = 'CODE93';
								break;
							case plus.barcode.CODE128:
								type = 'CODE128';
								break;
							case plus.barcode.ITF:
								type = 'ITF';
								break;
							case plus.barcode.MAXICODE:
								type = 'MAXICODE';
								break;
							case plus.barcode.PDF417:
								type = 'PDF417';
								break;
							case plus.barcode.RSS14:
								type = 'RSS14';
								break;
							case plus.barcode.RSSEXPANDED:
								type = 'RSSEXPANDED';
								break;
							default:
								type = '其它' + type;
								break;
						}
						result = result.replace(/\r\n/g, '');
						wo.evalJS("scaned('" + type + "','" + result + "','" + file + "','" + state + "');");
						$.back();
					}

					// 开始扫描
					ws.addEventListener('show', function() {
						scan = new plus.barcode.Barcode('bcid', [plus.barcode.QR, plus.barcode.EAN8, plus.barcode.EAN13, plus.barcode
							.AZTEC, plus.barcode.DATAMATRIX, plus.barcode.DATAMATRIX, plus.barcode.UPCA, plus.barcode.UPCE, plus.barcode
							.CODABAR, plus.barcode.CODE39, plus.barcode.CODE93, plus.barcode.CODE128, plus.barcode.ITF, plus.barcode.MAXICODE,
							plus.barcode.PDF417, plus.barcode.RSS14, plus.barcode.RSSEXPANDED
						], {
							frameColor: '#00FF00',
							scanbarColor: '#00FF00'
						});
						scan.onmarked = onmarked;
						scan.start({
							conserve: true,
							filename: '_doc/barcode/'
						});
						
					}, false);
					// 显示页面并关闭等待框
					ws.show('pop-in');
				});
			}(mui, document));
		</script>
		<!-- js代码 end -->

	</body>

</html>
